#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static char buf[1000000],*p1=buf,*p2=buf;
#define GC()	(p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
#define PC(x)	putchar(x)
ll read(){
	ll x = 0; char c = GC();
	while(c < '0' || c > '9') c = GC();
	while(c >= '0' && c <= '9'){
		x = (x << 3) + (x << 1) + c - '0'; c = GC();
	}
	return x;
}
void write(ll x){
	if(x >= 10) write(x / 10);
	PC(x % 10 + '0');
}
int T, n = 0;
namespace Sub0{
	ll sum = 0;
	set<ll> S;
	void solve(){
		int i;
		ll x, y, z, ans;
		set<ll>::iterator L, R;
		while(T--){
			x = read();
			if(S.count(x)){
				S.erase(x); sum -= x; n--;
			}else{
				S.insert(x); sum += x; n++;
			}
			if(n <= 1) ans = 0;
			else{
				ans = sum - (*(S.begin()) << 1);
				L = S.begin(); R = S.end();
				x = *L; y = 0; z = 0;
				for(i = 1; i < n - 1; i++){
					x += *(++L); y += *(--R);
					if(x <= y) break;
					z += x - y;
				}
				if(i < n - 1) ans -= z << 1;
				else ans -= z;
			}
			write(ans); PC('\n');
		}
	}
}
int main(){
	freopen("kte.in", "r", stdin);
	freopen("kte.out", "w", stdout);
	T = read();
	Sub0::solve();
	return 0;
}
